<?php

include "conexion.php";
include "errores.php";

// Fill up array with names
$nombres = "select distinct idAlumno,nombre,apellidoPat,apellidoMat,concat(apellidoPat,' ',apellidoMat,' ',nombre) nombreCompleto from alumno order by apellidoPat";
$nombresquery = mysql_query($nombres, $conexion);

//get the q parameter from URL
$q = $_GET["q"];

//lookup all hints from array if length of q>0
if (strlen($q) > 0) {
    $hint = "";
    $q = strtoupper(utf8_decode($q));
    $nombreslike = "select distinct idAlumno,nombre,apellidoPat,apellidoMat,concat(apellidoPat,' ',apellidoMat,' ',nombre) as nombreCompleto
  				from alumno 
				where concat(apellidoPat,' ',apellidoMat,' ',nombre) like '%$q%' 
				order by apellidoPat";
    $nombreslikequery = mysql_query($nombreslike, $conexion);
    while ($a = mysql_fetch_array($nombreslikequery)) {
        //if (strtolower($q)==strtolower(substr(utf8_encode($a['nombreCompleto']),0,strlen($q))))
        //{
        if ($hint == "") {
            $i = 1;
            $hint[$i] = utf8_encode($a['nombreCompleto']);
            $id[$i] = $a['idAlumno'];
            $i++;
        } else {
            $hint[$i] = utf8_encode($a['nombreCompleto']);
            //$hint=$hint." , ".$a['nombre'];
            $id[$i] = $a['idAlumno'];
            $i++;
        }
        //}
    }
}

// Set output to "no suggestion" if no hint were found
// or to the correct values
if ($hint == "") {
    $response = "no suggestion";
} else {
    $response = $hint;
    $responseId = $id;
}

//output the response

echo "<select name='alumnoSeleccionado' onChange='submit()'>";
echo "<option value='0'>---Elige Alumno--- </option>";
$j = 1;
foreach ($response as $k) {
    $k2 = $responseId[$j];
    $j++;
    echo "<option value='$k2'> $k </option>";
}
echo "</select>";


